'''
=====QTextEdit控制输入多行文本
QTextEdit控件
'''
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIntValidator, QDoubleValidator, QRegExpValidator
from PyQt5.QtCore import QRegExp
import sys


class QTextEditDemo(QWidget):
    def __init__(self):
        super(QTextEditDemo, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("QTextEdit控件演示")
        self.resize(300, 320)
        self.textEdit = QTextEdit()
        self.buttonText = QPushButton("显示文本")
        self.buttonHTML = QPushButton("显示HTML")

        self.buttonToText = QPushButton("获取文本")
        self.buttonToHTML = QPushButton("获取HTML")

        layout = QVBoxLayout()
        layout.addWidget(self.textEdit)
        layout.addWidget(self.buttonText)
        layout.addWidget(self.buttonHTML)

        layout.addWidget(self.buttonToText)
        layout.addWidget(self.buttonToHTML)
        self.setLayout(layout)
        self.buttonToText.clicked.connect(self.onClick_ButtonToText)
        self.buttonToHTML.clicked.connect(self.onClick_ButtonToHTML)

        self.buttonText.clicked.connect(self.onClick_ButtonText)
        self.buttonHTML.clicked.connect(self.onClick_ButtonHTML)

    def onClick_ButtonText(self):
        self.textEdit.setPlainText("Hello World")

    def onClick_ButtonHTML(self):
        self.textEdit.setHtml('<font color= "blue" size ="5">Hello World！！！           How are you?</font>')

    def onClick_ButtonToText(self):
        print(self.textEdit.toPlainText())

    def onClick_ButtonToHTML(self):
        print(self.textEdit.toHtml())


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('./img/juice.png'))
    main = QTextEditDemo()
    main.show()
    sys.exit(app.exec_())
